package com.mongo.pattern;

/**
 * @author: simon
 * @date: 2019/8/5 16:50
 */
public class BookShelfIterator implements Iterator {

    private BookShelf bookShelf;

    private int currIndex;

    public BookShelfIterator(BookShelf bookShelf) {
        this.bookShelf = bookShelf;
        currIndex = 0;
    }

    @Override
    public boolean hasNext() {
        if(currIndex < bookShelf.getLastIndex())
            return true;
        return false;
    }

    @Override
    public Object next() {
        Book book = bookShelf.getBookAtIndex(currIndex);
        currIndex++;
        return book;
    }
}
